#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\AAT.h>



static void *storeFromStruct;

static int recordNum;
void registerAAT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadAATRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerAAT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(AAT_FILENAME, SIZE_AAT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreAATRecFromStruct(void *vdStruct)
{
	registerAAT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetAATRec(), vdStruct, SIZE_AAT_REC);

}

void vdCopyAATRecFromStruct(void *vdStruct)
{
	registerAAT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetAATRec(), SIZE_AAT_REC);

}

int	inSaveAATRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerAAT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(AAT_FILENAME, SIZE_AAT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateAATRecFromStruct (void *vdStruct)
{
	int inRet;

	registerAAT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(AAT_FILENAME, SIZE_AAT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

char* szGetAutoAnsInitFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetAutoAnsInit();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((AAT_REC*)vdStruct)->szAutoAnsInit;
}

void vdSetAutoAnsInitFromStruct(const char* szAutoAnsInit, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAutoAnsInit(szAutoAnsInit);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((AAT_REC*)vdStruct)->szAutoAnsInit, szAutoAnsInit, sizeof(((AAT_REC*)NULL)->szAutoAnsInit)-1);
}

short shGetAutoAnsBaudRateFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetAutoAnsBaudRate();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((AAT_REC*)vdStruct)->shAutoAnsBaudRate;
}

void vdSetAutoAnsBaudRateFromStruct(short shAutoAnsBaudRate, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAutoAnsBaudRate(shAutoAnsBaudRate);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((AAT_REC*)vdStruct)->shAutoAnsBaudRate = shAutoAnsBaudRate;
}

short shGetAutoAnsFormatFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return shGetAutoAnsFormat();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((AAT_REC*)vdStruct)->shAutoAnsFormat;
}

void vdSetAutoAnsFormatFromStruct(short shAutoAnsFormat, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetAutoAnsFormat(shAutoAnsFormat);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((AAT_REC*)vdStruct)->shAutoAnsFormat = shAutoAnsFormat;
}

